MV_CC_RegisterEventCallBackEx

MV_CC_RegisterEventCallBackEx

Register single event callback function.

API Definition

int MV_CC_RegisterEventCallBackEx(
  void         *handle,
  const char   *pEventName,
  cbEvent      cbEvent,
  void         *pUser
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

pEventName

[IN] Event name

cbEvent

[IN] Callback function for receiving event information, see details below:

void(__stdcall* cbEvent)(
  MV_EVENT_OUT_INFO     *pEventInfo,
  void                  *pUser
);
pEventInfo

[OUT] Output event information, see enumeration MV_EVENT_OUT_INFO for details.

pUser

[OUT] User data

pUser

[IN] User data

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • Call this API to set the event callback function to get the event information, such as acquisition, exposure, and so on.

  • This API is supported by CameraLink device only for device offline event.

The following sample code is for reference only.

#include "MvCameraControl.h"

void __stdcall EvCallback(MV_EVENT_OUT_INFO *pEventInfo, void* pUser)
{
    printf("EventName:+%s",pEventInfo->EventName);
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all devices of specific transport protocol in the subnet
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Select the first found online device and create handle
    int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Register data callback function
     nRet = MV_CC_RegisterEventCallBackEx(m_handle,"ExposureEnd", EvCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //Connect to device
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //Other process...

    //Start image acquisition
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }
    //Other process...

     //Stop image acquisition
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //Close camera
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle and release resources
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

MV_CC_RegisterEventCallBackEx

Register single event callback function.

API Definition

int MV_CC_RegisterEventCallBackEx(
  void         *handle,
  const char   *pEventName,
  cbEvent      cbEvent,
  void         *pUser
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

pEventName

[IN] Event name

cbEvent

[IN] Callback function for receiving event information, see details below:

void(__stdcall* cbEvent)(
  MV_EVENT_OUT_INFO     *pEventInfo,
  void                  *pUser
);
pEventInfo

[OUT] Output event information, see enumeration MV_EVENT_OUT_INFO for details.

pUser

[OUT] User data

pUser

[IN] User data

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • Call this API to set the event callback function to get the event information, such as acquisition, exposure, and so on.

  • This API is supported by CameraLink device only for device offline event.

The following sample code is for reference only.

#include "MvCameraControl.h"

void __stdcall EvCallback(MV_EVENT_OUT_INFO *pEventInfo, void* pUser)
{
    printf("EventName:+%s",pEventInfo->EventName);
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all devices of specific transport protocol in the subnet
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }
    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Select the first found online device and create handle
    int nDeviceIndex = 0;
    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));
    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);
    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Register data callback function
     nRet = MV_CC_RegisterEventCallBackEx(m_handle,"ExposureEnd", EvCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBack fail [%x]\n", nRet);
        return;
    }

    //Connect to device
    unsigned int nAccessMode = MV_ACCESS_Exclusive;
    unsigned short nSwitchoverKey = 0;
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }

    //Other process...

    //Start image acquisition
     nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }
    //Other process...

     //Stop image acquisition
     nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //Close camera
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle and release resources
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}